#pragma once
#include <iostream>
#include <odb/core.hxx>
#include <odb/nullable.hxx>

namespace im
{

#pragma db object table("user")
    class User
    {
    public:
        User() {}
        User(const std::string &uid, const std::string &name, const std::string &pwd)
            : _user_id(uid), _nickname(name), _pwd(pwd) {}
        User(const std::string &uid, const std::string &phone)
            : _user_id(uid), _nickname(uid), _phone(phone) {}

        void user_id(const std::string &uid) { _user_id = uid; }
        std::string user_id() const { return _user_id; }

        void user_name(const std::string &name) { _nickname = name; }
        std::string user_name(){
            if (_nickname)
                return *_nickname;
            return std::string();
        }

        void password(const std::string &pwd) { _pwd = pwd; }
        std::string password(){
            if (_pwd)
                return *_pwd;
            return std::string();
        }

        void description(const std::string &description) { _description = description; }
        std::string description(){
            if (_description)
                return *_description;
            return std::string();
        }

        void phone(const std::string &phone) { _phone = phone; }
        std::string phone(){
            if (_phone)
                return *_phone;
            return std::string();
        }

        void avatar_id(const std::string &avatar_id) { _avatar_id = avatar_id; }
        std::string avatar_id(){
            if (_avatar_id)
                return *_avatar_id;
            return std::string();
        }

    private:
        friend class odb::access;
        #pragma db id auto
        unsigned int _id;
        #pragma db unique index type("VARCHAR(127)")
        std::string _user_id;
        #pragma db type("VARCHAR(63)")
        odb::nullable<std::string> _nickname;
        #pragma db type("VARCHAR(255)")
        odb::nullable<std::string> _pwd;
        #pragma db type("VARCHAR(255)")
        odb::nullable<std::string> _description;
        #pragma db unique type("VARCHAR(15)")
        odb::nullable<std::string> _phone;
        #pragma db type("VARCHAR(127)")
        odb::nullable<std::string> _avatar_id;
    };
}

// odb -d mysql --std c++11 --generate-query --generate-schema --profile boost/date-time .
